﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using V5_Model;
using V5_BLL;

namespace V5_EShop._Template.Default.Member
{
    public partial class Evaluate_CommentEdit : BasicPage
    {
        public int _productid = 0;
        public ModelProduct product = new ModelProduct();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.check_member_login())
            {
                Response.Redirect("/login.aspx?returnurl=" + HTTPS.GetCurrentUrl());
            }
            if (!this.IsPostBack)
            {
                //检查该用户是否买过这个商品
                _productid = Input.SetInt(Request["pid"]);
                product = new BLLProduct().GetModel(_productid);
                lblProductName.Text = product.ProductName;
                hfProductID.Value = product.ID.ToString();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            btnSave.Click += new EventHandler(btnSave_Click);
            base.OnInit(e);
        }

        private void Bind_CheckBuyProduct()
        {

        }

        void btnSave_Click(object sender, EventArgs e)
        {
            int int1 = 0, int2 = 0, int3 = 0, int4 = 0;
            if (rbtn1_1.Checked)
            {
                int1 = 1;
            }
            else if (rbtn1_2.Checked)
            {
                int1 = 2;
            }
            else if (rbtn1_3.Checked)
            {
                int1 = 3;
            }
            //
            if (rbtn2_1.Checked)
            {
                int2 = 1;
            }
            else if (rbtn2_2.Checked)
            {
                int2 = 2;
            }
            else if (rbtn2_3.Checked)
            {
                int2 = 3;
            }
            //
            if (rbtn3_1.Checked)
            {
                int3 = 1;
            }
            else if (rbtn3_2.Checked)
            {
                int3 = 2;
            }
            else if (rbtn3_3.Checked)
            {
                int3 = 3;
            }
            //
            if (rbtn4_1.Checked)
            {
                int4 = 1;
            }
            else if (rbtn4_2.Checked)
            {
                int4 = 2;
            }
            else if (rbtn4_3.Checked)
            {
                int4 = 3;
            }
            string commentTitle = this.txtCommentTitle.Text;
            string commentContent = this.txtCommentContent.Text;
            int ProductID = Input.SetInt(this.hfProductID.Value);
            if (ProductID > 0)
            {
                ModelProductComment m_productcomment = new ModelProductComment();
                BLLProductComment b_productcomment = new BLLProductComment();
                m_productcomment.ID = b_productcomment.GetMaxId();
                m_productcomment.CommentName = commentTitle;
                m_productcomment.CommentContent = commentContent;
                m_productcomment.AddDateTime = DateTime.Now;
                m_productcomment.CommentEmail = user.UserEmail;
                m_productcomment.CommentIP = HTTPS.GetIP;
                m_productcomment.MemberID = user.ID;
                m_productcomment.ProductID = ProductID;
                m_productcomment.Pmost = int1;
                m_productcomment.Pmost1 = int2;
                m_productcomment.Pmost2 = int3;
                m_productcomment.Pmost3 = int4;
                m_productcomment.Passed = 0;
                b_productcomment.Add(m_productcomment);
                Response.Redirect("/member/Evaluate_Comment.aspx");
            }
            Response.Redirect(HTTPS.ComeUrl);
        }
    }
}
